﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YXQ.Common;
using YXQ.Service;
using YXQ.Common.Extension;
namespace YXQ.Manager.Handler
{
    /// <summary>
    /// AdminHandler 的摘要说明
    /// </summary>
    public class AdminHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            AJAXJson rtnMessage = new AJAXJson();
            string opType = context.Request["OpType"];
            var controler = new ControlService(context);
            string msg = string.Empty;
            //string rtnMessage = string.Empty;
            //bool flg = false;
            if (!string.IsNullOrEmpty(opType))
            {
                switch (opType.ToLower())
                {
                    case "chklogin": 
                          
                        rtnMessage.ResultMessage= controler.UserLogin();
                        break;

                    
                   
                    case "menu":
                        //checked 为C#关键词 所以命名check要替换成checked
                        var menus = controler.GetMenu();

                        rtnMessage.ResultMessage = menus.Replace("check","checked");

                        break;
                    case "saveproject": 
                        rtnMessage.ResultMessage = controler.SaveProject();
                        break;
                    case "saveuser":
                        rtnMessage.ResultMessage = controler.SaveUser();
                        break;

                    case "saveuserright":
                        rtnMessage.ResultMessage = controler.SaveUserRight();
                        break;
                    case "savedepart":
                        rtnMessage.ResultMessage = controler.SaveDepart();
                        break;
                    case "savemessage":
                        rtnMessage.ResultMessage = controler.SaveMessage();
                        break;
                  
                    case "deldata":
                        rtnMessage.ResultMessage = controler.DelData();
                        break;
                    case "saveda":
                        rtnMessage.ResultMessage = controler.SaveDa();
                        break;

                    default: break;
                }
            }
            if (rtnMessage.ResultMessage == "[]") {
                rtnMessage.ResultMessage = "";
            }
            context.Response.ContentType = "text/json;charset=UTF-8;";
            switch (opType.ToLower()) {
                case "getproject":
                case "getuser":
                case "menu":
                case "getdepart":
                case "gettop":
                case "getmessage":
                case "deldata":
                    context.Response.Write(rtnMessage.ResultMessage);
                    break;

                default:
                    context.Response.Write(rtnMessage.ToJsonItem());
                    break;
            }

            
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}